@echo off

REM 启用延迟环境变量扩展
setlocal enabledelayedexpansion

REM 设置Java类路径，包含所有必要的依赖
set CLASSPATH=target/classes

REM 查找Maven本地仓库中的所有Spring Boot相关JAR文件
for /f "delims=" %%j in ('dir /s /b "%USERPROFILE%\.m2\repository\org\springframework\boot"\*.jar') do (
    set CLASSPATH=!CLASSPATH!;%%j
)

REM 查找Maven本地仓库中的所有依赖JAR文件
for /f "delims=" %%j in ('dir /s /b "%USERPROFILE%\.m2\repository\org\springframework"\*.jar') do (
    set CLASSPATH=!CLASSPATH!;%%j
)
for /f "delims=" %%j in ('dir /s /b "%USERPROFILE%\.m2\repository\mysql"\*.jar') do (
    set CLASSPATH=!CLASSPATH!;%%j
)
for /f "delims=" %%j in ('dir /s /b "%USERPROFILE%\.m2\repository\com\zaxxer\HikariCP"\*.jar') do (
    set CLASSPATH=!CLASSPATH!;%%j
)
for /f "delims=" %%j in ('dir /s /b "%USERPROFILE%\.m2\repository\jakarta"\*.jar') do (
    set CLASSPATH=!CLASSPATH!;%%j
)

REM 查找本地target/lib目录中的JAR文件（如果存在）
if exist target\lib\*.jar (
    for /f "delims=" %%j in ('dir /b "target\lib"\*.jar') do (
        set CLASSPATH=!CLASSPATH!;target\lib\%%j
    )
)

REM 输出类路径信息
echo Classpath set successfully

REM 运行应用程序
echo Starting application...
java -cp "!CLASSPATH!" com.downbox.BlindBoxApplication